package com.zbkj.service.service.impl;

import com.alibaba.fastjson.JSON;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.profile.DefaultProfile;
import com.google.gson.Gson;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * 1、服务功能：
 * 免费寄售、全球找货、免费置换、维修保养、评估鉴定
 * 姚远13311675687    蔡亮13795287678
 * 2、订单
 * 承享、供享、购买
 * 蔡亮13795287678   李婧洁13764164929
 * 3、资金往来
 * 购卡、充值、认购、提现
 * 郑立18930758311     崔婷婷15268163617   崔盈盈15857675603
 * 4、招商
 * 合作加盟、卡座预约
 * 蔡亮13795287678
 */
@Slf4j
@Service
public class AliSmsServiceImpl {

    /**
     * 1、服务功能：
     * 免费寄售、全球找货、免费置换、维修保养、评估鉴定
     * 姚远13311675687    蔡亮13795287678
     *
     * @param business
     */
    public void sendServiceMsg(String business) {
        this.sendMsg("13311675687", "姚远", business);
        this.sendMsg("13795287678", "蔡亮", business);
    }

    /**
     * 2、订单
     * 承享、供享、购买
     * 蔡亮13795287678   李婧洁13764164929
     *
     * @param business
     */
    public void sendOrderMsg(String business) {
        this.sendMsg("13764164929", "李婧洁", business);
        this.sendMsg("13795287678", "蔡亮", business);
    }

    /**
     * 3、资金往来
     * 购卡、充值、认购、提现
     * 郑立18930758311     崔婷婷15268163617   崔盈盈15857675603
     *
     * @param business
     */
    public void sendFundMsg(String business) {
        this.sendMsg("18930758311", "郑立", business);
        this.sendMsg("15268163617", "崔婷婷", business);
        this.sendMsg("15857675603", "崔盈盈", business);
    }

    /**
     * 4、招商
     * 合作加盟、卡座预约
     * 蔡亮13795287678
     *
     * @param business
     */
    public void sendAttractMsg(String business) {
        this.sendMsg("13795287678", "蔡亮", business);
    }

    /**
     * 发送短信
     *
     * @param phoneNumber
     * @param name
     * @param business
     */
    public void sendMsg(String phoneNumber, String name, String business) {

        // Please ensure that the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET are set.
        DefaultProfile profile = DefaultProfile.getProfile("cn-qingdao",
                "LTAI5tQZi35n7dE444dPy3kx",
                "LEh4JETmsSYzDsA82wJ73LoH2M4ccu");
        /** use STS Token
         DefaultProfile profile = DefaultProfile.getProfile(
         "<your-region-id>",           // The region ID
         System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),       // The AccessKey ID of the RAM account
         System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"),   // The AccessKey Secret of the RAM account
         System.getenv("ALIBABA_CLOUD_SECURITY_TOKEN"));     // STS Token
         **/

        IAcsClient client = new DefaultAcsClient(profile);

        SendSmsRequest request = new SendSmsRequest();
        request.setPhoneNumbers(phoneNumber);
        request.setSignName("上海惠屹珠宝科技");
        request.setTemplateCode("SMS_480390202");
        Map<String, String> map = new HashMap<>();
        map.put("name", name);
        map.put("business", business);
        request.setTemplateParam(JSON.toJSONString(map));

        try {
            SendSmsResponse response = client.getAcsResponse(request);
            log.info(new Gson().toJson(response));
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            log.info("ErrCode:" + e.getErrCode());
            log.info("ErrMsg:" + e.getErrMsg());
            log.info("RequestId:" + e.getRequestId());
        }

    }
}


